import time
from threading import Thread
from selenium import webdriver
from time import sleep
from idNumber import  IdNumber
from idName import  IdName

def func(name):
    print(f"{name}开始")
    sfz = IdNumber(1)
    ids = sfz.generate_myid()

    for index in range(len(ids)):
        # print( '当前水果 :', ids[index])
        browser = webdriver.Chrome()

        browser.get("http://booking.36zc.cn/yuyue/")
        sleep(1)

        browser.find_element_by_xpath('//*[@id="days"]/li[6]').click()

        sleep(1)

        browser.find_element_by_xpath('//*[@id="times"]/li[1]').click()

        sleep(1)

        browser.find_element_by_xpath('//*[@id="context"]/div[2]/button').click()

        name = IdName(1)
        nickname = name.random_name()

        browser.find_element_by_xpath('//*[@id="person-info"]/tr/td[3]/div/input').send_keys(nickname)

        sleep(1)

        browser.find_element_by_xpath('//*[@id="person-info"]/tr/td[5]/div/input').send_keys(ids[index])

        sleep(1)

        browser.find_element_by_xpath('//*[@id="app"]/div/div/div[2]/div/form/div[3]/input').click()

        sleep(1)

        browser.find_element_by_xpath('//*[@id="app"]/div/div/div[2]/div/div/input[2]').click()

        browser.quit()

    print(f"{name}结束")


if __name__ == '__main__':
    t1 = Thread(target=func, args=("线程1",))
    t2 = Thread(target=func, args=("线程2",))
    t1.start()
    t2.start()
    print("主线程结束")